package com.example.util;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class SQLImporter {
    public static void main(String[] args) throws Exception {
        // 加载MySQL驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        
        String url = "jdbc:mysql://localhost:3306/kepucom?useSSL=false&serverTimezone=UTC";
        String user = "root";
        String password = "123456";
        String sqlFilePath = "D:/gitee_projects/2222/new-kepucom/src/main/resources/quiz_question_full_init.sql";

        String sql = new String(Files.readAllBytes(Paths.get(sqlFilePath)), "UTF-8");
        try (Connection conn = DriverManager.getConnection(url, user, password);
             Statement stmt = conn.createStatement()) {
            for (String s : sql.split(";")) {
                if (!s.trim().isEmpty()) {
                    stmt.execute(s);
                }
            }
            System.out.println("SQL导入成功！");
        }
    }
} 